home *** CD-ROM | disk | FTP | other *** search
- {
-
- TechTutor2
- Alien code, a simple (not working) example.
-
- Coding by P.Bestebroer
- FreeWare
-
- This source will not work on it's own, it just shows how to
- do alien-code into you'r game...
- The source code was ripped from one of my game-projects, but
- because of this little tech-info I extruded variables wich where
- needed in my game, but are not allways used.
-
- Contacting:
-
- HTTP://people.zeelandnet.nl/rpb/
- EMAIL:just4fun@zeelandnet.nl
-
- }
- PROGRAM Tech02;
-
- USES CRT,OBJECTS;
- {─────────────────────────────────────────────────────────────────────────────}
- {
- First create the BASE_ALIEN variables
- }
- TYPE Pactor = ^Tactor; { this is the Base_Alien code }
- Tactor = object
- Xposition,
- Yposition : integer; { Xposition and Yposition }
- Xstart,Ystart: integer; { X+Y start positions }
- Xspeed,
- Yspeed : real; { Xspeed and Yspeed }
- xdir,ydir : shortint; { direction of movement }
- AI : byte; { AI state }
- energy : byte; { energy of the alien }
- ID : byte; { alien number }
- killed : boolean; { if actor is out of loop }
- I_frame,
- f_Frame, { Animation frame data }
- a_Frame,
- c_frame,
- t_frame,
- s_Frame : byte;
- n_frame : shortint;
- cycle : boolean;
-
- CONSTRUCTOR INIT(xp,yp:integer); { initialisation of alien }
- PROCEDURE sub_init; Virtual; { for some extra init }
- PROCEDURE animate; Virtual; { animate the images }
- FUNCTION see_if_hit:boolean; Virtual; { see if hit by bullet }
- FUNCTION PLAYER_HIT:boolean; Virtual; { see if hitting the player}
- PROCEDURE putit; Virtual; { draw the alien }
- PROCEDURE movement; Virtual; { moving the alien }
- PROCEDURE acting; Virtual; { the AI procedure }
- DESTRUCTOR DONE; { For erasing alien }
- END;
- {=-=-=-=-= Now create the Specific_Alien variables =-=-=-=-=}
- TYPE PGroundWalker = ^TGroundWalker; { A ground-walker (ie. soldier) }
- TGroundWalker = object(TACTOR) { is based on the Base_Actor }
- PROCEDURE SUB_INIT; Virtual; { For extra variables initialisation }
- PROCEDURE Acting; VIRTUAL; { For the AI of the Ground-Walkers }
- END;
-
- PFlying = ^TFlying; { A flying enemie }
- TFlying = object(TACTOR) { is based on the Base_Actor }
- PROCEDURE SUB_INIT; Virtual; { for extra variables initialisation }
- PROCEDURE Acting; VIRTUAL; { for the AI of the Ground-Walkers }
- end;
-
-
- VAR act : array[0..255] of Pactor; { array of the actors }
- actor_a : byte; { amount of actors in game }
- {────────────────────────────────────────────────────────────────────────────}
- {
- These are the procedures wich could be used....
- }
- CONSTRUCTOR TACTOR.Init(xp,yp:integer); { to initialise an alien }
- BEGIN
- {
- Set the position variables,
- the energy, the default values (ie. Killed=False)
- }
- END;
-
- PROCEDURE TACTOR.SUB_INIT; { this is replaced by the specific_alien code }
- BEGIN
- ABSTRACT;
- END;
-
- PROCEDURE TACTOR.ANIMATE; { For the image-animations }
- BEGIN
- {
- Animate the alien walking, flying, shooting, etc...
- }
- END;
-
- FUNCTION TACTOR.PLAYER_HIT:boolean; { see if hitting the player }
- BEGIN
- {
- Check on collision between the player and the alien
- }
- END;
-
- FUNCTION TACTOR.SEE_IF_HIT:boolean; { See if hit by a bullet }
- BEGIN
- {
- Walk thru the bullets, and check on collision with the alien..
- if hit set the KILLED flag to TRUE
- }
- END;
-
- PROCEDURE TACTOR.PUTIT; { Draw the alien on screen }
- BEGIN
- {
- Draw the current frame-image of the alien on screen
- }
- END;
-
- PROCEDURE TACTOR.MOVEMENT; { This is for the moving of the specific_aliens }
- BEGIN
- ABSTRACT
- END;
-
-
- PROCEDURE TACTOR.ACTING; { This will handle the AI of the specific_alien }
- BEGIN
- ABSTRACT;
- END;
-
-
- DESTRUCTOR TACTOR.DONE; { For erasing the alien from memory }
- BEGIN
- END;
-
-
- {────────────────────────────────────────────────────────────────────────────}
- { The custom-home-made-do-it-yourself enemy code }
- {────────────────────────────────────────────────────────────────────────────}
- PROCEDURE TGroundWalker.SUB_INIT;
- BEGIN
- {
- Put the specific initialisation for the GroundWalking enemy
- in this little procedure...
- }
- END;
-
- PROCEDURE TGroundWalker.Acting;
- BEGIN
- {
- Put all code for movement, collision detection and other things in this
- procedure...
- This is the "core" of the GroundWalking enemy, or call it his
- Artificial Intelligence routines
- }
- END;
- {────────────────────────────────────────────────────────────────────────────}
- PROCEDURE TFlying.SUB_INIT;
- BEGIN
- {
- Put the specific initialisation for the Flying enemy
- in this little procedure...
- }
- END;
-
- PROCEDURE TFlying.Acting;
- BEGIN
- {
- Put all code for movement, collision detection and other things in this
- procedure...
- This is the "core" of the Flying enemy, or call it his
- Artificial Intelligence routines
- }
- END;
- {────────────────────────────────────────────────────────────────────────────}
- {
- This code will intialise all the different aliens
-
- Expects : AI Number of the alien and other init variables
- Returns : a Pointer to the new TACTOR type
-
- }
- FUNCTION AddActor(ai:byte;xp,yp:integer):Pactor;
- BEGIN
- Addactor:=NIL;
- case ai of
- 1 : addActor:=new(PGroundWalker,init(xp,yp)); { first alien type }
- 2 : addActor:=new(PFlying,init(xp,yp)); { second alien type }
- { ... }
- end;
- END;
- {────────────────────────────────────────────────────────────────────────────}
- {
-
- Process the actor_list
-
- Expects: Nothing
- Returns: Nothing
-
- }
- PROCEDURE DoActors;
- VAR i : word;
- BEGIN
- if actor_a=0 then exit; { no actors to process }
- i:=1; { start with first actor }
- while i<actor_a+1 do begin
- with act[i]^ do begin
- if not KILLED then begin { if alien still lives, }
- Acting; { make it act (moving, shooting, etc...) }
- PutIt; { and draw it. PUTIT could be cald from within ACTING}
- end;
- end;
- inc(i); { go to next actor in the array }
- end;
- END;
- {────────────────────────────────────────────────────────────────────────────}
- BEGIN
- while port[$60]<>156 do ;
- textcolor(7); textbackground(0); clrscr;
- writeln('TechTutor #2');
- writeln('written by P.Bestebroer, Just4Fun Productions');
- writeln('');
- writeln('This examples contains procedures for some great aliens/objects and things');
- writeln;
- writeln('Just like the previous tutor, this example needs some extra work aswell');
- writeln('Although the examples work, they wont display anything on the screen.');
- writeln('There are also no real "acting/movement" procedures because that is');
- writeln('upto you to implement (the easiest and most fun job!)');
- writeln;
- writeln('You should use a great VGA unit (SuperFX engine for example ;) and ');
- writeln('implement the things like drawing the objects');
- writeln;
- writeln('Watch out for the other techtutors...');
- writeln;
- writeln('Press a key');
-
- writeln;
- writeln;
- writeln;
- writeln('----------------------------------');
- writeln('Contacting: just4fun@zeelandnet.nl');
- writeln('http://people.zeelandnet.nl/rpb ');
- writeln('----------------------------------');
- repeat until port[$60]<>156;
-
- END.
-